﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using System.Configuration;
using IQKS.AWP.BusinessObject;
using IQKS.AWP.BusinessAccessLayer;

public partial class Assessor_AssessorCalendar : System.Web.UI.Page
{
    AssessorCalendarBO objACBO = new AssessorCalendarBO();
    AssessorCalendarBAL objACBAL = new AssessorCalendarBAL();

    protected void Page_Load(object sender, EventArgs e)
    {
        hidCheckSessMsg.Visible = false;
        CalendarExtender1.Format = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB").DateTimeFormat.ShortDatePattern;
        CalendarExtender2.Format = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB").DateTimeFormat.ShortDatePattern;
        if (!this.IsPostBack)
        {
            DataTable dt = new DataTable();

            SetAssessorExistingTimeSlots("");
            dt.Columns.AddRange(new DataColumn[10] { new DataColumn("GDStartDate"), new DataColumn("FirstHalfHr"), new DataColumn("FirstHalfMn")
                , new DataColumn("FirstSelected"), new DataColumn("SecondHalfHr"), new DataColumn("SecondHalfMn"), new DataColumn("SecondSelected"), new DataColumn("Remark"),new DataColumn("StartDate"),new DataColumn("CandidateName") });
            //dt.Columns.Add("Date");
            //dt.Columns.Add("FirstHalfTime");
            //dt.Columns.Add("SecondHalfTime");
            ViewState["AssesserCalendar"] = dt;
            this.BindGrid();
            //dt1.Columns.AddRange(new DataColumn[2] { new DataColumn("GDStartDate"), new DataColumn("GDSDay") });
            //dt1.Columns.AddRange(new DataColumn[1] { new DataColumn("GDStartDate") });
            /**/
            //ViewState["CandidateSelectAssessordate"] = dt1;
            //this.BindGrid1();
            btnSave.Visible = false;
            btnCancel.Visible = false;
            btnSave.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btnSave, null) + ";");
        }
        txtStartDate.Attributes.Add("readonly", "readonly");
        txtEndDate.Attributes.Add("readonly", "readonly");
        txtSearchFDate.Attributes.Add("readonly", "readonly");
        txtSearchTDate.Attributes.Add("readonly", "readonly");
    }

    #region "Control Events"
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            objACBO.StartDate = txtStartDate.Text.Trim();
            objACBO.EndDate = txtEndDate.Text.Trim();
            objACBO.UserID = CommonUtility.GetLoggedOnUserId();

            string strDateCheck = Convert.ToString(objACBAL.CheckAssessorAvailabilityByDate(objACBO));
            if (strDateCheck == "NO")
            {
                int days = 0;
                bool OneDay = true;
                if (txtEndDate.Text.Trim() == txtStartDate.Text.Trim())
                {
                    days = 0;
                }
                else
                {
                    days = Convert.ToDateTime(txtEndDate.Text.Trim()).Date.Subtract(Convert.ToDateTime(txtStartDate.Text.Trim())).Days;
                    OneDay = false;
                }
                ViewState["StartDate"] = txtStartDate.Text.Trim();
                ViewState["EndDate"] = txtEndDate.Text.Trim();

                DataTable dt1 = new DataTable(); ;
                dt1.Columns.AddRange(new DataColumn[16] { new DataColumn("GDStartDate"), new DataColumn("FirstHalfHr"), new DataColumn("FirstHalfMn")
                    , new DataColumn("FirstSelected"), new DataColumn("SecondHalfHr"), new DataColumn("SecondHalfMn"), new DataColumn("SecondSelected"), new DataColumn("Remark"),new DataColumn("StartDate"),new DataColumn("AssessorCalendarDetailID") ,new DataColumn("IsActive"),new DataColumn("ActiveStatus"),new DataColumn("CandidateID"),new DataColumn("CandidateName"),new DataColumn("CanFirstHalfCheck"),new DataColumn("CanSecondHalfCheck")});
                ViewState["AssesserCalendar"] = dt1;

                DataTable dt = (DataTable)ViewState["AssesserCalendar"];

                for (int i = 0; i <= days; i++)
                {
                    dt.Rows.Add(Convert.ToDateTime(txtStartDate.Text.Trim()).AddDays(i).ToString("dd/MM/yyyy"), "10", "00", "0", "02", "00", "0", "", Convert.ToDateTime(txtStartDate.Text.Trim()).AddDays(i).ToString("dd/MM/yyyy -dddd"), "0", 0, false, 0, "");
                }
                if (days > 0 || OneDay)
                {
                    btnSave.Visible = true;
                    btnCancel.Visible = true;
                }
                ViewState["AssesserCalendar"] = dt;

                this.BindGrid();
                ViewState["StartDate"] = txtStartDate.Text.Trim();
                ViewState["EndDate"] = txtEndDate.Text.Trim();
                txtStartDate.Text = string.Empty;
                txtEndDate.Text = string.Empty;
                lblDtRnge.Text = "";
                hidCheckSessMsg.Visible = true;
            }
            else
            {
                lblDtRnge.Text = strDateCheck;
                hidCheckSessMsg.Visible = false;
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            objACBO.StartDate = ViewState["StartDate"].ToString();
            objACBO.EndDate = ViewState["EndDate"].ToString();
            objACBO.Remark = txtRemark.Text.Trim();
            objACBO.UserID = CommonUtility.GetLoggedOnUserId();
            objACBO.AssessorCalendarDetails = GetAssessorCalendarDetails();

            if (ViewState["AssessorCalendarID"] != null)
            {
                objACBO.AssessorCalendarID = Convert.ToInt32(ViewState["AssessorCalendarID"]);
            }
            else
            {
                objACBO.AssessorCalendarID = 0;
            }

            string result = Convert.ToString(objACBAL.SetAssessorCalendar(objACBO));

            if (result == "SUCCESS")
            {
                ClearForm();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Availability Time slot saved Successfully.');", true);
                SetAssessorExistingTimeSlots("");
            }
            if (result == "FiveDaysRequired")
            {
                ClearForm();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Availability Time slot saved Successfully. Kindly Note-Minimum 5 days slots should be avilable');", true);
                SetAssessorExistingTimeSlots("");
            }
            if (result == "ERROR")
            {
                ClearForm();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Error occured while saving.');", true);
                SetAssessorExistingTimeSlots("");
            }


        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        ClearForm();
        btnAdd.Visible = true;
        CalendarExtender1.Enabled = true;
        CalendarExtender2.Enabled = true;
        tdHeaderMessage.InnerHtml = " <h3>Block New Dates</h3>";
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        SetAssessorExistingTimeSlots("SEARCH");
        gvAssessorCalendar.Visible = false;
        txtRemark.Text = string.Empty;
        txtStartDate.Text = string.Empty;
        txtEndDate.Text = string.Empty;
        CalendarExtender1.Enabled = true;
        CalendarExtender2.Enabled = true;
        tdHeaderMessage.InnerHtml = " <h3>Block New Dates</h3>";
    }
    #endregion

    #region "ReUsable methods"
    protected void BindGrid()
    {

        gvAssessorCalendar.DataSource = (DataTable)ViewState["AssesserCalendar"];
        gvAssessorCalendar.DataBind();

        foreach (GridViewRow row in gvAssessorCalendar.Rows)
        {
            CheckBox chFH = (CheckBox)row.FindControl("chkApproveFirstHalf");
            CheckBox chSH = (CheckBox)row.FindControl("chkApproveSecondHalf");
            DropDownList dlFHr = (DropDownList)row.FindControl("ddlFHHour");
            DropDownList dlFMn = (DropDownList)row.FindControl("ddlFHMinute");
            DropDownList dlSHr = (DropDownList)row.FindControl("ddlSHHour");
            DropDownList dlSMn = (DropDownList)row.FindControl("ddlSHMinute");
            if (chFH != null && chSH != null && dlFHr != null && dlFMn != null && dlSHr != null && dlSMn != null)
            {
                chFH.Checked = false;
                chSH.Checked = false;
                dlFHr.SelectedIndex = 9;
                dlFMn.SelectedIndex = 0;
                dlSHr.SelectedIndex = 1;
                dlSMn.SelectedIndex = 0;
            }
        }
        gvAssessorCalendar.Columns[0].InsertVisible = true;

        gvAssessorCalendar.Columns[0].Visible = false;
    }
    protected void SetAssessorExistingTimeSlots(string type)
    {
        DataTable dt1 = new DataTable();

        if (type == "")
        {
            DateTime FD = DateTime.Now.AddDays(Convert.ToDouble(ConfigurationManager.AppSettings["AssessorCalendarSearchBefore"]) * (-1));
            DateTime TD = DateTime.Now.AddDays(Convert.ToDouble(ConfigurationManager.AppSettings["AssessorCalendarSearchAfter"]));

            txtSearchFDate.Text = FD.ToString("dd/MM/yyyy");
            txtSearchTDate.Text = TD.ToString("dd/MM/yyyy");
        }
        objACBO.UserID = CommonUtility.GetLoggedOnUserId();
        objACBO.AssessorCalendarID = 0;
        objACBO.StartDate = txtSearchFDate.Text.Trim();
        objACBO.EndDate = txtSearchTDate.Text.Trim();

        dt1 = objACBAL.GetAssessorCalendarDetails(objACBO).Tables[0];
        if (dt1 != null)
        {
            gvAssessorAvailableCalendarList.DataSource = dt1;
            gvAssessorAvailableCalendarList.DataBind();
            if (dt1.Rows.Count > 0)
                lblTotalDays.Text = dt1.Rows[0]["TotalDays"].ToString();
            else
                lblTotalDays.Text = "0";
        }
    }
    protected void BindGridForEdit(long AssessorCalendarID)
    {
        objACBO.UserID = CommonUtility.GetLoggedOnUserId();
        objACBO.AssessorCalendarID = AssessorCalendarID;
        objACBO.StartDate = txtSearchFDate.Text.Trim();
        objACBO.EndDate = txtSearchTDate.Text.Trim();
        DataSet ds = objACBAL.GetAssessorCalendarDetails(objACBO);
        ViewState["AssessorCalendarID"] = AssessorCalendarID;
        if (ds != null)
        {
            if (ds.Tables.Count > 1)
            {
                if (ds.Tables[1].Rows.Count > 0)
                {
                    ViewState["AssessorDetailsEdit"] = ds.Tables[1];
                    gvAssessorCalendar.DataSource = ds.Tables[1];
                    gvAssessorCalendar.DataBind();

                    txtStartDate.Text = ds.Tables[0].Rows[0]["GDStartDate"].ToString();
                    ViewState["StartDate"] = ds.Tables[0].Rows[0]["GDStartDate"].ToString();
                    CalendarExtender1.Enabled = false;
                    txtEndDate.Text = ds.Tables[0].Rows[0]["GDEndDate"].ToString();
                    ViewState["EndDate"] = ds.Tables[0].Rows[0]["GDEndDate"].ToString();
                    CalendarExtender2.Enabled = false;
                    btnAdd.Visible = false;
                    txtRemark.Text = ds.Tables[0].Rows[0]["GDRemark"].ToString();
                    btnSave.Visible = true;
                    btnCancel.Visible = true;
                }
            }
        }
    }
    protected void ClearForm()
    {
        txtSearchFDate.Text = "";
        txtSearchTDate.Text = "";
        txtStartDate.Text = "";
        txtEndDate.Text = "";
        txtRemark.Text = "";
        gvAssessorCalendar.DataSource = null;
        gvAssessorCalendar.DataBind();
        btnAdd.Visible = true;
        btnSave.Visible = false;
        btnCancel.Visible = false;
        ViewState["AssessorCalendarID"] = null;
        ViewState["AssessorDetailsEdit"] = null;
        ViewState["AssesserCalendar"] = null;
        ViewState["StartDate"] = null;
        ViewState["EndDate"] = null;
        CalendarExtender1.Enabled = true;
        CalendarExtender2.Enabled = true;
    }
    protected string GetAssessorCalendarDetails()
    {
        string AssessorCalendarDetails = string.Empty;

        DataTable dt = (DataTable)ViewState["AssesserCalendar"];
        if (dt != null && ViewState["AssessorDetailsEdit"] == null && dt.Rows.Count > 0)
        {
            foreach (GridViewRow row in gvAssessorCalendar.Rows)
            {
                CheckBox chkFH = (CheckBox)row.FindControl("chkApproveFirstHalf");
                if (chkFH.Checked)
                {
                    DropDownList ddlFHR = (DropDownList)row.FindControl("ddlFHHour");
                    DropDownList ddlFMN = (DropDownList)row.FindControl("ddlFHMinute");
                    dt.Rows[row.RowIndex][1] = ddlFHR.SelectedValue.ToString() + ":" + ddlFMN.SelectedValue.ToString() + " AM";
                    dt.Rows[row.RowIndex][3] = true;
                }
                else
                {
                    dt.Rows[row.RowIndex][1] = dt.Rows[row.RowIndex][1].ToString() + ":00 AM";
                    dt.Rows[row.RowIndex][3] = false;
                }

                CheckBox chkSH = (CheckBox)row.FindControl("chkApproveSecondHalf");
                if (chkSH.Checked)
                {
                    DropDownList ddlSHR = (DropDownList)row.FindControl("ddlSHHour");
                    DropDownList ddlSMN = (DropDownList)row.FindControl("ddlSHMinute");
                    dt.Rows[row.RowIndex][4] = ddlSHR.SelectedValue.ToString() + ":" + ddlSMN.SelectedValue.ToString() + " PM";
                    dt.Rows[row.RowIndex][6] = true;
                }
                else
                {
                    dt.Rows[row.RowIndex][4] = dt.Rows[row.RowIndex][4].ToString() + ":00 PM";
                    dt.Rows[row.RowIndex][6] = false;
                }
                TextBox txtEDRemark = (TextBox)row.FindControl("txtEveryDayRemark");
                if (txtEDRemark != null)
                {
                    dt.Rows[row.RowIndex][7] = txtEDRemark.Text.Trim();
                }
            }
            ViewState["AssesserCalendar"] = dt;
            AssessorCalendarDetails = CommonUtility.ConvertDatatableToXML(dt);
        }

        DataTable dtEdit = (DataTable)ViewState["AssessorDetailsEdit"];
        if (dtEdit != null)
        {
            foreach (GridViewRow row in gvAssessorCalendar.Rows)
            {
                CheckBox chkFH = (CheckBox)row.FindControl("chkApproveFirstHalf");
                if (chkFH.Checked)
                {
                    DropDownList ddlFHR = (DropDownList)row.FindControl("ddlFHHour");
                    DropDownList ddlFMN = (DropDownList)row.FindControl("ddlFHMinute");
                    dtEdit.Rows[row.RowIndex][6] = ddlFHR.SelectedValue.ToString() + ":" + ddlFMN.SelectedValue.ToString() + " AM";
                    dtEdit.Rows[row.RowIndex][8] = true;
                }
                else
                {
                    dtEdit.Rows[row.RowIndex][8] = false;
                }

                CheckBox chkSH = (CheckBox)row.FindControl("chkApproveSecondHalf");
                if (chkSH.Checked)
                {
                    DropDownList ddlSHR = (DropDownList)row.FindControl("ddlSHHour");
                    DropDownList ddlSMN = (DropDownList)row.FindControl("ddlSHMinute");
                    dtEdit.Rows[row.RowIndex][7] = ddlSHR.SelectedValue.ToString() + ":" + ddlSMN.SelectedValue.ToString() + " PM";
                    dtEdit.Rows[row.RowIndex][9] = true;
                }
                else
                {
                    dtEdit.Rows[row.RowIndex][9] = false;
                }
                TextBox txtEDRemark = (TextBox)row.FindControl("txtEveryDayRemark");
                if (txtEDRemark != null)
                {
                    dtEdit.Rows[row.RowIndex][11] = txtEDRemark.Text.Trim();
                }
            }
            ViewState["AssessorDetailsEdit"] = dtEdit;
            AssessorCalendarDetails = CommonUtility.ConvertDatatableToXML(dtEdit);
        }

        return AssessorCalendarDetails;
    }

    #endregion

    #region "GridView Events"

    protected void gvAssessorAvailableCalendarList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToUpper() == "EDITDATE")
        {
            tdHeaderMessage.InnerHtml = " <h3>Update Dates</h3>";
            gvAssessorCalendar.Visible = true;
            gvAssessorCalendar.Columns[0].Visible = true;
            int AssessorCalendarID = Convert.ToInt32(e.CommandArgument);
            if (AssessorCalendarID >= 0)
            {
                BindGridForEdit(AssessorCalendarID);
            }
        }
    }
    protected void gvAssessorCalendar_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnkDelete = (LinkButton)e.Row.FindControl("lnkDelete");
            HyperLink hrfFirstHalf = (HyperLink)e.Row.FindControl("FirstHalfCandidateName");
            HyperLink hrfSecondHalf = (HyperLink)e.Row.FindControl("SecondHalfCandidateName");
            bool blnIsActive = (Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "IsActive")) == 0);

            if (blnIsActive)
            {
                lnkDelete.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to activate " + DataBinder.Eval(e.Row.DataItem, "StartDate") + " date?')");
                lnkDelete.Attributes.Add("title", "Slot is deleted and click to activate again");
            }
            else
            {
                lnkDelete.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete " + DataBinder.Eval(e.Row.DataItem, "StartDate") + " date?')");
                lnkDelete.Attributes.Add("title", "Click to delete slot");
            }


            CheckBox chFH = (CheckBox)e.Row.FindControl("chkApproveFirstHalf");
            CheckBox chSH = (CheckBox)e.Row.FindControl("chkApproveSecondHalf");
            DropDownList dlFHr = (DropDownList)e.Row.FindControl("ddlFHHour");
            DropDownList dlFMn = (DropDownList)e.Row.FindControl("ddlFHMinute");
            DropDownList dlSHr = (DropDownList)e.Row.FindControl("ddlSHHour");
            DropDownList dlSMn = (DropDownList)e.Row.FindControl("ddlSHMinute");
            Label lblCanFirstHalfCheck = (Label)e.Row.FindControl("CanFirstHalfCheck");
            Label lblCanSecondHalfCheck = (Label)e.Row.FindControl("CanSecondHalfCheck");

            if (ViewState["AssessorDetailsEdit"] != null)
            {
                DataTable dt = (DataTable)ViewState["AssessorDetailsEdit"];
                if (chFH != null)
                {
                    chFH.Checked = Convert.ToBoolean(dt.Rows[e.Row.RowIndex]["FirstSelected"]);
                    if (blnIsActive == false)
                    {
                        ((TableCell)chFH.Parent).Style.Add("background-color", "lightgreen");
                        ((TableCell)chFH.Parent).Style.Add("color", "black");
                    }
                }
                if (chSH != null)
                {
                    chSH.Checked = Convert.ToBoolean(dt.Rows[e.Row.RowIndex]["SecondSelected"]);
                    if (blnIsActive == false)
                    {
                        ((TableCell)chSH.Parent).Style.Add("background-color", "lightgreen");
                        ((TableCell)chSH.Parent).Style.Add("color", "black");
                    }
                }
                if (dlFHr != null)
                {
                    dlFHr.SelectedIndex = dlFHr.Items.IndexOf(dlFHr.Items.FindByValue(dt.Rows[e.Row.RowIndex]["FirstHalfHr"].ToString()));
                }
                if (dlFMn != null)
                {
                    dlFMn.SelectedIndex = dlFMn.Items.IndexOf(dlFMn.Items.FindByValue(dt.Rows[e.Row.RowIndex]["FirstHalfMn"].ToString()));
                }
                if (dlSHr != null)
                {
                    dlSHr.SelectedIndex = dlSHr.Items.IndexOf(dlSHr.Items.FindByValue(dt.Rows[e.Row.RowIndex]["SecondHalfHr"].ToString()));
                }
                if (dlSMn != null)
                {
                    dlSMn.SelectedIndex = dlSMn.Items.IndexOf(dlSMn.Items.FindByValue(dt.Rows[e.Row.RowIndex]["SecondHalfMn"].ToString()));
                }

                if (hrfFirstHalf != null)
                {
                    if (Convert.ToBoolean(dt.Rows[e.Row.RowIndex]["CanFirstHalfCheck"]) == true)
                    {
                        hrfFirstHalf.Visible = true;
                    }
                    else
                    {
                        hrfFirstHalf.Visible = false;
                    }

                }
                if (hrfSecondHalf != null)
                {
                    if (Convert.ToBoolean(dt.Rows[e.Row.RowIndex]["CanSecondHalfCheck"]) == true)
                    {
                        hrfSecondHalf.Visible = true;
                    }
                    else
                    {
                        hrfSecondHalf.Visible = false;
                    }
                }

                if (Convert.ToDateTime(dt.Rows[e.Row.RowIndex]["GDDateYYYYMMDD"]).CompareTo(System.DateTime.Today) < 0)
                {
                    chFH.Enabled = false;
                    chSH.Enabled = false;
                    dlFHr.Enabled = false;
                    dlFMn.Enabled = false;
                    dlSHr.Enabled = false;
                    dlSMn.Enabled = false;
                    lnkDelete.Visible = false;
                    lnkDelete.Enabled = false;
                }
                else if (blnIsActive)
                {
                    lnkDelete.Style.Add("color", "white");
                    lnkDelete.Style.Add("text-decoration", "underline");
                    e.Row.Style.Add("color", "white");
                    e.Row.Style.Add("background-color", "#FF6600");
                }
            }
        }
    }

    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        try
        {
            objACBO.UserID = CommonUtility.GetLoggedOnUserId();
            objACBO.AssessorCalendarDetails = GetAssessorCalendarUpdateDetails();
            string result = Convert.ToString(objACBAL.CheckAssessorAvailabilityUpdate(objACBO));

            if (result != "SUCCESS")
            {
                args.IsValid = false;
                CustomValidator1.ErrorMessage = "Candidate already selected these dates ( " + result.Trim().Substring(1) + " ).";
                return;
            }
            else
            {
                args.IsValid = true;
            }
        }
        catch
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Error while saving Record : ');", true);
        }


    }

    protected string GetAssessorCalendarUpdateDetails()
    {
        string AssessorCalendarDetails = string.Empty;

        DataTable dtEdit = (DataTable)ViewState["AssessorDetailsEdit"];
        if (dtEdit != null)
        {
            foreach (GridViewRow row in gvAssessorCalendar.Rows)
            {
                CheckBox chkFH = (CheckBox)row.FindControl("chkApproveFirstHalf");
                if (chkFH.Checked)
                {
                    DropDownList ddlFHR = (DropDownList)row.FindControl("ddlFHHour");
                    DropDownList ddlFMN = (DropDownList)row.FindControl("ddlFHMinute");
                    dtEdit.Rows[row.RowIndex][6] = ddlFHR.SelectedValue.ToString() + ":" + ddlFMN.SelectedValue.ToString() + " AM";
                    dtEdit.Rows[row.RowIndex][8] = true;
                }
                else
                {
                    dtEdit.Rows[row.RowIndex][8] = false;
                }

                CheckBox chkSH = (CheckBox)row.FindControl("chkApproveSecondHalf");
                if (chkSH.Checked)
                {
                    DropDownList ddlSHR = (DropDownList)row.FindControl("ddlSHHour");
                    DropDownList ddlSMN = (DropDownList)row.FindControl("ddlSHMinute");
                    dtEdit.Rows[row.RowIndex][7] = ddlSHR.SelectedValue.ToString() + ":" + ddlSMN.SelectedValue.ToString() + " PM";
                    dtEdit.Rows[row.RowIndex][9] = true;
                }
                else
                {
                    dtEdit.Rows[row.RowIndex][9] = false;
                }

                TextBox txtEDRemark = (TextBox)row.FindControl("txtEveryDayRemark");
                if (txtEDRemark != null)
                {
                    dtEdit.Rows[row.RowIndex][11] = txtEDRemark.Text.Trim();
                }

                Label lblAssessorCalID = (Label)row.FindControl("lblAssessorCalendarDetailID");
                if (lblAssessorCalID != null)
                {
                    dtEdit.Rows[row.RowIndex][12] = lblAssessorCalID.Text.Trim();
                }

            }
            ViewState["AssessorDetailsEdit"] = dtEdit;
            AssessorCalendarDetails = CommonUtility.ConvertDatatableToXML(dtEdit);
        }

        return AssessorCalendarDetails;
    }

    #endregion
    protected void gvAssessorCalendar_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        long lgActivityID = (long)gvAssessorCalendar.DataKeys[e.RowIndex].Value;
        int intStatus = (((Label)(gvAssessorCalendar.Rows[e.RowIndex].FindControl("lblActiveStatus"))).Text.ToUpper() == "ACTIVE" ? 0 : 1);

        string strReturnValue;
        strReturnValue = DeleteAssessorCalender(lgActivityID, intStatus);


        if (strReturnValue == "SUCCESS")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Selected date has been " + (intStatus == 0 ? "deleted" : "activated") + " Successfully.');", true);
        }
        if (strReturnValue == "ALREADY")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('You can not delete selected date. Candidate already selected this date.');", true);
        }
        if (strReturnValue == "ERROR")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Error occured while saving.');", true);
        }

        BindGridForEdit(((long)ViewState["AssessorCalendarID"]));

    }

    private string DeleteAssessorCalender(long lgActivityID, int intStatus)
    {
        string strReturnValue;
        strReturnValue = (string)objACBAL.DeleteAssessorCalendarByID(lgActivityID, intStatus);
        return strReturnValue;
    }

    public string GetViewtUrl(object objCandidateID)
    {

        string strPath = string.Empty;

        if (Convert.ToInt64(objCandidateID) > 0)
        {
            strPath = "~/home/CandidateDetailsReg.aspx?CandidateID=" + CommonUtility.Encrypt(Convert.ToString(objCandidateID), true);
        }
        else
        {
            strPath = "";
        }
        return strPath;
    }
}